<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>LORDSEE</title>
    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/icon.css" />
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript">
    var contextPath = function() {
        return  "/" + location.pathname.split("/")[1];
    }
    
    var _menus = {};
    //初始化左侧
    function InitLeftMenu() {
    	var obj = $.ajax({url:contextPath()+"/auth/getLoginUserFunctionTree",async:false});
    	var res = eval("(" + obj.responseText + ")");
    	var functionTree =  res.function_tree.root;
     	//_menus = createMenuTree(functionTree); 
     	
    	for (var i in functionTree.children){
    		if (functionTree.children[i].object.function_name=='运营合规内控') _menus = createMenuTree(functionTree.children[i]);
    	}
    	
    	$("#nav").accordion({animate:false});
    	
        $.each(_menus.menus, function(i, n) {
    		var menulist ='';
    		menulist +='<ul class="easyui-tree">';
            $.each(n.menus, function(j, o) {
    			menulist += '<li><div><a ref="'+o.menuid+'" href="#" rel="' + o.url + '" style="text-decoration:none;"><span class="icon '+o.icon+'" >&nbsp;</span><span class="nav">' + o.menuname + '</span></a></div></li> ';
            });
    		menulist += '</ul>';

    		$('#nav').accordion('add', {
                title: n.menuname,
                content: menulist,
                iconCls: 'icon ' + n.icon
            });

        });

    	$('.easyui-accordion li a').click(function(){
    		var tabTitle = $(this).children('.nav').text();
    		var url = $(this).attr("rel");
    		var menuid = $(this).attr("ref");
    		var icon = getIcon(menuid,icon);
    		addTab(tabTitle,url,icon);
    		$('.easyui-accordion li div').removeClass("selected");
    		$(this).parent().addClass("selected");
    	}).hover(function(){
    		$(this).parent().addClass("hover");
    	},function(){
    		$(this).parent().removeClass("hover");
    	});

    	//选中第一个
    	var panels = $('#nav').accordion('panels');
    	var t = panels[0].panel('options').title;
        $('#nav').accordion('select', t);
    }
    
	//构建菜单树(递归方式) BEGIN
 	function createMenuTree(node){
 		var menuTree= {};
		if (node.level=='1'){
			menuTree.menus = [];
			for (var i in node.children){
				menuTree.menus.push( createMenuTree(node.children[i]));
			}
		} else if (node.level=='2') {
			menuTree.menuid = node.object.function_id;
			menuTree.menuname = node.object.function_name;
			menuTree.icon = 'icon-sys';
			menuTree.menus = [];
			for (var i in node.children){
				menuTree.menus.push( createMenuTree(node.children[i]));
			}
		} else if (node.level=='3') {
			menuTree.menuid = node.object.function_id;
			menuTree.menuname = node.object.function_name;
			menuTree.icon = 'icon-nav';
			menuTree.menus = [];
			for (var i in node.children){
				menuTree.menus.push( createMenuTree(node.children[i]));
			}
		} else if (node.level=='4') {
			menuTree.menuid = node.object.function_id;
			menuTree.menuname = node.object.function_name;
			menuTree.icon = 'icon-nav';
			menuTree.url = contextPath()+"/"+node.object.function_url;
		}
 		return menuTree;
 	}
 	//构建菜单树(递归方式)  END
    
    //获取左侧导航的图标
    function getIcon(menuid){
    	var icon = 'icon ';
    	$.each(_menus.menus, function(i, n) {
    		 $.each(n.menus, function(j, o) {
    		 	if(o.menuid==menuid){
    				icon += o.icon;
    			}
    		 })
    	})

    	return icon;
    }

    function addTab(subtitle,url,icon){
    	if(!$('#tabs').tabs('exists',subtitle)){
    		$('#tabs').tabs('add',{
    			title:subtitle,
    			content:createFrame(url),
    			closable:true,
    			icon:icon
    		});
    	}else{
    		$('#tabs').tabs('select',subtitle);
    		$('#mm-tabupdate').click();
    	}
    	tabClose();
    }

    function createFrame(url)
    {
    	var s = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
    	return s;
    }

    function tabClose()
    {
    	/*双击关闭TAB选项卡*/
    	$(".tabs-inner").dblclick(function(){
    		var subtitle = $(this).children(".tabs-closable").text();
    		$('#tabs').tabs('close',subtitle);
    	})
    	/*为选项卡绑定右键*/
    	$(".tabs-inner").bind('contextmenu',function(e){
    		$('#mm').menu('show', {
    			left: e.pageX,
    			top: e.pageY
    		});

    		var subtitle =$(this).children(".tabs-closable").text();

    		$('#mm').data("currtab",subtitle);
    		$('#tabs').tabs('select',subtitle);
    		return false;
    	});
    }
    //绑定右键菜单事件
    function tabCloseEven()
    {
    	//刷新
    	$('#mm-tabupdate').click(function(){
    		var currTab = $('#tabs').tabs('getSelected');
    		var url = $(currTab.panel('options').content).attr('src');
    		$('#tabs').tabs('update',{
    			tab:currTab,
    			options:{
    				content:createFrame(url)
    			}
    		})
    	})
    	//关闭当前
    	$('#mm-tabclose').click(function(){
    		var currtab_title = $('#mm').data("currtab");
    		$('#tabs').tabs('close',currtab_title);
    	})
    	//全部关闭
    	$('#mm-tabcloseall').click(function(){
    		$('.tabs-inner span').each(function(i,n){
    			var t = $(n).text();
    			$('#tabs').tabs('close',t);
    		});
    	});
    	//关闭除当前之外的TAB
    	$('#mm-tabcloseother').click(function(){
    		$('#mm-tabcloseright').click();
    		$('#mm-tabcloseleft').click();
    	});
    	//关闭当前右侧的TAB
    	$('#mm-tabcloseright').click(function(){
    		var nextall = $('.tabs-selected').nextAll();
    		if(nextall.length==0){
    			//msgShow('系统提示','后边没有啦~~','error');
    			alert('后边没有啦~~');
    			return false;
    		}
    		nextall.each(function(i,n){
    			var t=$('a:eq(0) span',$(n)).text();
    			$('#tabs').tabs('close',t);
    		});
    		return false;
    	});
    	//关闭当前左侧的TAB
    	$('#mm-tabcloseleft').click(function(){
    		var prevall = $('.tabs-selected').prevAll();
    		if(prevall.length==0){
    			alert('到头了，前边没有啦~~');
    			return false;
    		}
    		prevall.each(function(i,n){
    			var t=$('a:eq(0) span',$(n)).text();
    			$('#tabs').tabs('close',t);
    		});
    		return false;
    	});

    	//退出
    	$("#mm-exit").click(function(){
    		$('#mm').menu('hide');
    	})
    }

    //弹出信息窗口 title:标题 msgString:提示信息 msgType:信息类型 [error,info,question,warning]
    function msgShow(title, msgString, msgType) {
    	$.messager.alert(title, msgString, msgType);
    }
    	

        //设置登录窗口
        function openPwd() {
            $('#w').window({
                title: '修改密码',
                width: 300,
                modal: true,
                shadow: true,
                closed: true,
                height: 190,
                resizable:false
            });
        }
        //关闭登录窗口
        function closePwd() {
            $('#w').window('close');
        }

        

        //修改密码
        function serverLogin() {
            var $oldpass = $('#txtOldPass');
            var $newpass = $('#txtNewPass');
            var $rePass = $('#txtRePass');

            if ($oldpass.val() == '') {
                msgShow('系统提示', '请输入原密码！', 'warning');
                return false;
            }
            if ($newpass.val() == '') {
                msgShow('系统提示', '请输入新密码！', 'warning');
                return false;
            }
            if ($rePass.val() == '') {
                msgShow('系统提示', '请在一次输入新密码！', 'warning');
                return false;
            }

            if ($newpass.val() != $rePass.val()) {
                msgShow('系统提示', '新密码两次输入不一至！请重新输入', 'warning');
                return false;
            }
            
            $.ajax({
        		type:'POST',
        		url:contextPath()+'/auth/modifyLoginUserPassword',
        	    data:{	oldpassword:$oldpass.val(),
        	    		newpassword:$newpass.val()},
        	    dataType:'json',
        	    beforeSend: function () {
        			$.messager.progress({ 
						title: '提示', 
        				msg: '操作进行中，请稍候……', 
        				text: '' 
        			});
        	    },
        	    complete: function () {
        			$.messager.progress('close');
        	    },
        	    success: function(result){
        			if (result) {
                        msgShow('系统提示', '恭喜，密码修改成功！<br>您的新密码为：' + $newpass.val(), 'info');
                        $newpass.val('');
                        $rePass.val('');
                        closePwd();
        			} else {
                        msgShow('系统提示', '密码修改失败！', 'info');
        			}
        		}
        	});            
        }

        $(function() {

        	var res1 = $.ajax({url:contextPath()+"/auth/getLoginUser",async:false});
        	var res2 = $.ajax({url:contextPath()+"/auth/getLoginRole",async:false});      
        	var res3 = eval("(" + res1.responseText + ")");
        	var res4 = eval("(" + res2.responseText + ")");
        	var loginUserName = res3.login_user.name_cn;
        	var loginRoleName = res4.login_role.role_name;
        	$("#LoginUserInfo").html(loginUserName + "|" + loginRoleName);
        	
            openPwd();

            $('#editpass').click(function() {
                $('#w').window('open');
            });

            $('#btnEp').click(function() {
                serverLogin();
            })

			$('#btnCancel').click(function(){closePwd();})

            $('#loginOut').click(function() {
                $.messager.confirm('系统提示', '您确定要退出本次登录吗?', function(r) {
                    if (r) {
                        location.href = contextPath()+'/authlogin/logout';
                    }
                });
            })
            
            //初始化左侧菜单
    		InitLeftMenu();
    		tabClose();
    		tabCloseEven();
        });
    </script>
</head>

<body class="easyui-layout" style="overflow-y: hidden"  scroll="no">
<noscript>
<div style=" position:absolute; z-index:100000; height:2046px;top:0px;left:0px; width:100%; background:white; text-align:center;">
    <img src="../ShellEasyUI/images/noscript.gif" alt='抱歉，请开启脚本支持！' />
</div>
</noscript>
    <div region="north" split="true" border="false" style="overflow: hidden; height: 30px;
        background: url(../ShellEasyUI/images/blue.png) #7f99be repeat-x center 50%;
        line-height: 20px;color: #fff; font-family: Verdana, 微软雅黑,黑体">
        <span style="padding-left:10px; font-size: 18px; ">
        	<img src="resources/images/lordsee.png" height="20" align="absmiddle" />
        	LORDSEE SYSTEM
        </span>
        <span style="float:right; padding-right:20px;" class="head">当前用户：
		<span id="LoginUserInfo">即将显示当前登录的用户</span>
			<a href="#" id="editpass" style="color: #fff;">[修改密码]</a>
          	<a href="#" id="loginOut" style="color: #fff;">[安全退出]</a>
        </span>
    </div>
    <div region="south" split="true" style="height: 20px; background: #D2E0F2; ">   
    </div>
    <div region="west" hide="true" split="true" title="导航菜单" style="width:180px;" id="west">
	<div id="nav" class="easyui-accordion" fit="true" border="false">
		<!--  导航内容 -->
	</div>
    </div>
    <div id="mainPanle" region="center" style="background: #eee; overflow-y:hidden">
        <div id="tabs" class="easyui-tabs"  fit="true" border="false" >
			<div title="首页" style="overflow:hidden;color:red;">
				<!--  
				<iframe scrolling="auto"  frameborder="0"  src="dashboard.html" style="width:100%;height:100%;"></iframe>
				-->
        		<img src="resources/images/lordsee.png" height="500" align="absmiddle" />
			</div>
		</div>
    </div>
    
    
    <!--修改密码窗口-->
    <div id="w" class="easyui-window" title="修改密码" collapsible="false" minimizable="false"
        maximizable="false" icon="icon-save"  style="width: 300px; height: 250px; padding: 5px;
        background: #fafafa;">
        <div class="easyui-layout" fit="true">
            <div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
                <table cellpadding=3>
                    <tr>
                        <td>原密码：</td>
                        <td><input id="txtOldPass"  type="password" class="txt01" /></td>   
                    </tr>
                    <tr>
                        <td>新密码：</td>
                        <td><input id="txtNewPass" type="password" class="txt01" /></td>   
                    </tr>
                    <tr>
                        <td>确认密码：</td>
                        <td><input id="txtRePass" type="password"  class="txt01" /></td>
                    </tr>
                </table>
            </div>
            <div region="south" border="false" style="text-align: right; height: 30px; line-height: 30px;">
                <a id="btnEp" class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" >确定</a> 
                <a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)">取消</a>
            </div>
        </div>
    </div>

	<div id="mm" class="easyui-menu" style="width:150px;">
		<div id="mm-tabupdate">刷新</div>
		<div class="menu-sep"></div>
		<div id="mm-tabclose">关闭</div>
		<div id="mm-tabcloseall">全部关闭</div>
		<div id="mm-tabcloseother">除此之外全部关闭</div>
		<div class="menu-sep"></div>
		<div id="mm-tabcloseright">当前页右侧全部关闭</div>
		<div id="mm-tabcloseleft">当前页左侧全部关闭</div>
		<div class="menu-sep"></div>
		<div id="mm-exit">退出</div>
	</div>


</body>
</html>